<html>
<head><meta charset="utf-8"><title>Reliably testing that futures run concurrently? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html">Reliably testing that futures run concurrently?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206521058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206521058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206521058">(Aug 10 2020 at 22:31)</a>:</h4>
<p>I'm trying to write a test to ensure that two futures run concurrently, rather than sequentially. They're futures to spawn processes.</p>



<a name="206521134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206521134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206521134">(Aug 10 2020 at 22:32)</a>:</h4>
<p>I'd like to figure out a more reliable, and faster, way to test that than just spawning two futures running <code>sleep 1</code>  and making sure that it takes less than 1.5 seconds.</p>



<a name="206521404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206521404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206521404">(Aug 10 2020 at 22:36)</a>:</h4>
<p>maybe create a <a href="https://doc.rust-lang.org/std/time/struct.Duration.html">https://doc.rust-lang.org/std/time/struct.Duration.html</a> before and after and check <a href="https://doc.rust-lang.org/std/time/struct.Duration.html#method.checked_sub">https://doc.rust-lang.org/std/time/struct.Duration.html#method.checked_sub</a> ?</p>



<a name="206521433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206521433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206521433">(Aug 10 2020 at 22:36)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> Checking the duration isn't the problem. I'm trying to find a different solution that doesn't involve sleeping.</p>



<a name="206521440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206521440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206521440">(Aug 10 2020 at 22:36)</a>:</h4>
<p>oh I see</p>



<a name="206521444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206521444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206521444">(Aug 10 2020 at 22:36)</a>:</h4>
<p>yeah not sure, sorry</p>



<a name="206521462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206521462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206521462">(Aug 10 2020 at 22:37)</a>:</h4>
<p>/me ponders a solution involving pipes.</p>



<a name="206522817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206522817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206522817">(Aug 10 2020 at 22:55)</a>:</h4>
<p>Figured it out.</p>



<a name="206522930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206522930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206522930">(Aug 10 2020 at 22:57)</a>:</h4>
<p>Spawned <code>/bin/sh -c "read line"</code> as the first process, and <code>/bin/false</code> as the second one. Combined the futures with <code>or</code> and confirmed that the result I get back is from <code>/bin/false</code>.</p>



<a name="206522945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206522945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206522945">(Aug 10 2020 at 22:57)</a>:</h4>
<p>(as opposed to hanging)</p>



<a name="206527387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206527387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206527387">(Aug 11 2020 at 00:01)</a>:</h4>
<p>You could have the futures return <code>std::thread::current().id()</code>, then compare</p>



<a name="206538529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206538529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206538529">(Aug 11 2020 at 04:12)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> The problem wasn't that they were running on the same thread. The problem was that they were running sequentially on the same thread rather than concurrently on the same thread.</p>



<a name="206538533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206538533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206538533">(Aug 11 2020 at 04:12)</a>:</h4>
<p>Bug due to interesting interaction with the kernel. Turns out that setting a pidfd to <code>O_NONBLOCK</code> does nothing.</p>



<a name="206538682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206538682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206538682">(Aug 11 2020 at 04:17)</a>:</h4>
<p>Ah, ok. From the sleeping I thought you meant to block one thread and let something run on another. I guess that could be an async sleep though.</p>



<a name="206538737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206538737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206538737">(Aug 11 2020 at 04:18)</a>:</h4>
<p>I was spawning a separate process running <code>/bin/sleep</code>. ;)</p>



<a name="206538739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Reliably%20testing%20that%20futures%20run%20concurrently%3F/near/206538739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Reliably.20testing.20that.20futures.20run.20concurrently.3F.html#206538739">(Aug 11 2020 at 04:18)</a>:</h4>
<p>Just to have something that took a while.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>